/**
 * 
 */
package com.hospital.proxy;

import java.util.List;

import com.hospital.dao.IExpertDao;
import com.hospital.dao.impl.ExpertDaoImpl;
import com.hospital.dbc.DatabaseConnection;
import com.hospital.vo.Expert;

/**
 * @author Administrator
 *
 */
public class ExpertDaoProxy implements IExpertDao {
	IExpertDao dao = null;
	DatabaseConnection dbc = null;
	public ExpertDaoProxy() {
		try {
			this.dbc = new DatabaseConnection();
		} catch (Exception e) {
			e.printStackTrace();
		}
		this.dao = new ExpertDaoImpl(this.dbc.getConnection());
	}
	/* (non-Javadoc)
	 * @see com.hospital.dao.IExpertDao#doCreate(com.hospital.vo.Expert)
	 */
	@Override
	public boolean doCreate(Expert expert) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doCreate(expert);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}

	/* (non-Javadoc)
	 * @see com.hospital.dao.IExpertDao#doUpdate(com.hospital.vo.Expert)
	 */
	@Override
	public boolean doUpdate(Expert expert) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doUpdate(expert);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}

	/* (non-Javadoc)
	 * @see com.hospital.dao.IExpertDao#doDel(int)
	 */
	@Override
	public boolean doDel(int eid) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doDel(eid);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}

	/* (non-Javadoc)
	 * @see com.hospital.dao.IExpertDao#findAll(java.lang.String, int, int)
	 */
	@Override
	public List<Expert> findAll(String keyWord, int startIndex, int count)
			throws Exception {
		List<Expert> list = null;
		try {
			list = this.dao.findAll(keyWord, startIndex, count);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return list;
	}

	/* (non-Javadoc)
	 * @see com.hospital.dao.IExpertDao#findById(int)
	 */
	@Override
	public Expert findById(int eid) throws Exception {
		Expert exp = null;
		try {
			exp = this.dao.findById(eid);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return exp;
	}
	@Override
	public int count(String keyWord) throws Exception {
		int count = 0;
		try {
			count = this.dao.count(keyWord);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return count;
	}
	@Override
	public List<Expert> findAllByKid(int kid, int startIndex, int count)
			throws Exception {
		List<Expert> list = null;
		try {
			list = this.dao.findAllByKid(kid, startIndex, count);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return list;
	}
	@Override
	public int count(int kid) throws Exception {
		int count = 0;
		try {
			count = this.dao.count(kid);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return count;
	}

}
